package com.shijun.im.http;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2017/9/14 0014.
 */

    public class CustomConverterFactory<T> extends Converter.Factory {
        //默认为String的Class对象
        private Class clazz = String.class;

        private CustomConverterFactory() {}

        public  CustomConverterFactory(Class<T> clazz) {
           this.clazz = clazz;
        }

        @Override
        public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            return new CustomResponseBodyConverter<T>(clazz);
        }

        @Override
        public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
            return new StringRequestBodyConverter();
        }
    }